#pragma once

#include <unistd.h>

class FileGuard {
private:
    int &_fd;

public:
    FileGuard(int &fd) : _fd(fd){};

    ~FileGuard() {
        if (_fd > 0) {
            ::close(_fd);
            _fd = -1;
        }
    }
};
